//
//  MySettingsViewController.m
//  WholesalerApp
//
//  Created by CccDaxIN on 2016/11/2.
//  Copyright © 2016年 macox. All rights reserved.
//

#import "MySettingsViewController.h"
#import "MyMessageViewController.h"
#import "FeedBackViewController.h"
#import "MyWalleViewController.h"
#import "MyWalleModel.h"
#import "BalanceCashViewController.h"
#import "TermServiceViewController.h"
#import "AboutUsViewController.h"
#import "LoginViewController.h"
@interface MySettingsViewController ()
{
    NSString *yueER;
}
@end

@implementation MySettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    /**背景图圆角
     */
    [self.backgroundView.layer setMasksToBounds:YES];
    self.backgroundView.layer.cornerRadius = 15;
    self.navigationController.tabBarController.tabBar.tintColor = [UIColor colorWithHue:0.23 saturation:0.65 brightness:0.71 alpha:1.00];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    [self requestDataMyWalle];
    _shopName.text = SHOPNAME;
    
    //店铺logo
    if ([SHOPLOGO  isEqual: @"http://121.42.204.177:9999(null)"]) {
        [_logoImageButton setImage:[UIImage imageNamed:@"gandaji"] forState:UIControlStateNormal];
    }else{
        [_logoImageButton.layer setMasksToBounds:YES];
        [_logoImageButton.layer setCornerRadius:30.0];//设置矩形四个圆角半径
        NSString *imageStr = [NSString stringWithFormat:@"%@",SHOPLOGO];
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]];
        [_logoImageButton setImage:[UIImage imageWithData:data] forState:UIControlStateNormal];
    }
}
#pragma  mark -- 请求数据
- (void)requestDataMyWalle{
    NSDictionary *param = @{@"ShouJiHao":GETPHONE,@"Duuid":GETUUID,@"Token":GETTOKEN};
    [GDJHttpTool get:MineInfo params:param success:^(id responseObj) {
        NSLog(@"我的钱包 ：%@", responseObj);
        NSLog(@"%@", param);
        if ([[responseObj objectForKey:@"Err"] intValue]) {
            
        }else{
            NSDictionary *dataArr = [responseObj objectForKey:@"MineInfo"];
            MyWalleModel *model = [MyWalleModel mj_objectWithKeyValues:dataArr];
            _MYbalance.text = [NSString stringWithFormat:@"%@元",model.ShopYuE] ;
            yueER =  [NSString stringWithFormat:@"%@元",model.ShopYuE] ;
            _turnoverVolume.text = [NSString stringWithFormat:@"%@",model.TodayTotal] ;
            _accumulatedIncome.text = [NSString stringWithFormat:@"%@",model.LeiJiShouRu] ;
            _transactionOrder.text = [NSString stringWithFormat:@"%@",model.OrderCount];
            _withdrawals.text = [NSString stringWithFormat:@"%@",model.LeiJiTiXian] ;
            if (model.NotReadMessage == 0) {
                _MYmessageImage.image = [UIImage imageNamed:@"消息"];
            }else{
                _MYmessageImage.image = [UIImage imageNamed:@"xiaoxi"];
            }
        }
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

#pragma mark -- 我的钱包
- (IBAction)MYwalletAction:(id)sender {
    BalanceCashViewController *balanceCashVC = [[BalanceCashViewController alloc]init];
    NSLog(@"++________%@", yueER);
    balanceCashVC.MoneyAccount = yueER;
    self.hidesBottomBarWhenPushed=YES;
   
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
    [self.navigationController pushViewController:balanceCashVC animated:YES];
    self.hidesBottomBarWhenPushed=NO;
}

- (IBAction)MYwalletORnewsORfeedbackORordersORaboutUsButton:(UIButton *)sender {
    switch (sender.tag) {
        case 1501:{
            NSLog(@"我的消息");
            MyMessageViewController *myMessage = [[MyMessageViewController alloc]init];
            [self.navigationController pushViewController:myMessage animated:YES];
        }
            break;
        case 1502:{
            NSLog(@"服务条款");
            TermServiceViewController *termServiceVC = [[TermServiceViewController alloc]init];
            [self.navigationController pushViewController:termServiceVC animated:YES];
        }
            break;
        case 1503:{
            NSLog(@"意见反馈");
            FeedBackViewController *feedBackVC = [[FeedBackViewController alloc]init];
            [self.navigationController pushViewController:feedBackVC animated:YES];
        }
            break;
        case 1504:{
            NSLog(@"关于我们");
            AboutUsViewController *aboutUs = [[AboutUsViewController alloc]init];
            [self.navigationController pushViewController:aboutUs animated:YES];
        }
            break;
        case 1505:{
            NSLog(@"联系我们");
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"感谢" message:@"欢迎致电我们,收到您的来电是我们的荣幸" preferredStyle:UIAlertControllerStyleActionSheet];
            [alert addAction:[UIAlertAction actionWithTitle:@"座机1:0539-295 2317" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSString *contacts_phone = @"05392952317";
                NSString *num = [[NSString alloc] initWithFormat:@"telprompt://%@",contacts_phone];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"座机2:0539-295 2318" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSString *num = [[NSString alloc] initWithFormat:@"telprompt://05392952318"];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"下次再打吧" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:nil];
            }]];
            [self presentViewController:alert animated:YES completion:nil];
        }
            break;
        case 1506:{
            NSLog(@"退出账号");
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认退出" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
            [alert addAction:[UIAlertAction actionWithTitle:@"退出账号" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [[NSUserDefaults standardUserDefaults]setObject:nil forKey: @"Token"];
                LoginViewController *login = [[LoginViewController alloc]init];
                [self.navigationController pushViewController:login animated:YES];
                self.tabBarController.tabBar.hidden = YES;
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:nil];
            }]];
            [self presentViewController:alert animated:YES completion:nil];
        }
            break;
        default:
            break;
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
